package com.hades.example.java.refactoring.before.c10.c10_15_replace_exception_with_test;

import java.util.EmptyStackException;
import java.util.Stack;

public class ResourcePool {
    Stack<Resource> _available = new Stack<>();
    Stack<Resource> _allocated = new Stack<>();

    Resource getResource() {
        Resource result;
        try {
            result = _available.pop();
            _allocated.push(result);
            return result;
        } catch (EmptyStackException e) {
            result = new Resource("new created");
            _allocated.push(result);
            return result;
        }
    }
}